package com.smalls.newvideotwo.db;

import com.smalls.newvideotwo.NewDTVApp;
import com.smalls.newvideotwo.util.LogUtil;
import com.smalls.newvideotwo.utils.Tools;

import org.xutils.DbManager;
import org.xutils.DbManager.DaoConfig;
import org.xutils.DbManager.DbUpgradeListener;
import org.xutils.x;

import java.io.File;

public class DbUtils {
    public static final String DB_NAME_USER_VOD = "user_vod.db";

    public static DbManager getDbManager(String dbName) {
        return x.getDb(new DaoConfig().setDbName(dbName).setDbDir(new File(getDbPath())).setDbVersion(1).setDbUpgradeListener(new DbUpgradeListener() {
            public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
            }
        }));
    }

    private static String getDbPath() {

        File file=null;

        file=new File(NewDTVApp.getApp().getFilesDir()+"/databases");
        if (!file.exists() || file.isFile()) {
            file.mkdirs();
            Tools.chmodPath(file.getAbsolutePath());
        }

        LogUtil.d("aaaa","file.getAbsolutePath()="+file.getAbsolutePath());
        return file.getAbsolutePath();
    }
}
